package com.kill.servicescript.task

import android.app.Notification
import android.app.PendingIntent.CanceledException
import android.view.accessibility.AccessibilityEvent
import android.view.accessibility.AccessibilityNodeInfo
import com.kill.servicescript.ScriptServer

fun onTast(event: AccessibilityEvent, server: ScriptServer){
    when (event.eventType) {
        AccessibilityEvent.TYPE_NOTIFICATION_STATE_CHANGED ->
            if (event.parcelableData != null && event.parcelableData is Notification) {
                val contentIntent = (event.parcelableData as Notification).contentIntent
                try {
                    contentIntent.send()
                } catch (e: CanceledException) {
                    e.printStackTrace()
                }
            }
    }
    val rootNodeInfo : AccessibilityNodeInfo = server.rootInActiveWindow;
}

/**
 * 根据Text搜索所有符合条件的节点, 模糊搜索方式
 */
fun findNodesByText(text: String, rootNodeInfo : AccessibilityNodeInfo): List<AccessibilityNodeInfo>? {
    val nodeInfo = rootNodeInfo
    return nodeInfo?.findAccessibilityNodeInfosByText(text)
}


// 循环执行任务方法
fun onListTask(){

}